/**
 * @Description: 公用组件快速生成脚本
 */
const fs = require('fs');
const path = require('path');

const basePath = path.resolve(__dirname, '../src');

const componentName = process.argv[2]; // 获取第一个命令行参数
const capsComponentName = componentName.substring(0, 1).toUpperCase() + componentName.substring(1);
if (!componentName) {
  console.log('需要输入待创建组件的名称');
  console.log('示例：npm run cpn component');
  process.exit(0);
}

/**
 * @msg: vue页面模版
 */
const vueTemplate = `<template>
  <div class="${componentName}-wrap">
    {{data.componentName}}
  </div>
</template>

<script lang="ts">
  import { Component, Vue, Prop } from 'vue-property-decorator';
  import { Getter, Action } from 'vuex-class';

  @Component({})
  export default class ${capsComponentName} extends Vue {

    @Prop({
      required: false,
      default: '',
    }) name!: string

    private componentName: string = '${componentName}';

    private created() {
    }

    private activated() {
    }

    private mounted() {
    }

  }
</script>

<style lang="scss">
  @import "@/assets/style/variables";

  .${componentName}-wrap {
    width: 100%;
  }
</style>

`;

process.chdir(`${basePath}/components/common`);
fs.writeFileSync(`${componentName}.vue`, vueTemplate);

process.exit(0);
